package com.zyb.qiyu.user.provider.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyb.qiyu.live.common.interfaces.ConvertUtils;
import com.zyb.qiyu.user.dto.UserDTO;
import com.zyb.qiyu.user.provider.dao.mapper.UserMapper;
import com.zyb.qiyu.user.provider.dao.po.UserPO;
import com.zyb.qiyu.user.provider.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName UserServiceImpl
 * @Author zhaoyb
 * @Date 2024-01-15
 * @Version 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserPO> implements IUserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public UserDTO getByUserId(Long userId) {
        if (userId == null) {
            throw new IllegalArgumentException("userId不能为空");
        }
//        UserPO userPO = getById(userId);


        return ConvertUtils.convert(userMapper.selectById(userId), UserDTO.class);
    }

    @Override
    public String test() {
        System.out.println("~~~~~~~~~~~test  Dubbo service~~~~~~~~~");
        return "success";
    }


    @Override
    public boolean updateUserInfo(UserDTO userDTO) {
        if (userDTO == null || userDTO.getUserId() == null) {
            return false;
        }
        return this.updateById(ConvertUtils.convert(userDTO, UserPO.class));
    }

    @Override
    public boolean insertUserInfo(UserDTO userDTO) {
        return this.save(ConvertUtils.convert(userDTO, UserPO.class));
    }
}
